﻿$(function() {
	var app = angular.module('testCaseApp', [ 'toaster', 'ngAnimate' ]);
	app
			.controller(
					'testCaseCtrl',
					function($scope, $http, $filter, toaster) {
						$scope.isShowEditBtn = true;// 默认全部状态
						$scope.onlySeeSelf = true;// 默认只看没过期的
						$scope.ssfordemand = 1;

						// raido点击方法
						$scope.radioClick = function(x) {
							$scope.ssfordemand = x.target.value;
						};

						$scope.radioClickadd = function(x) {
							$scope.statusFordemandadd = x.target.value;
						};
						// 编辑关键结果的时候，在上头显示当前输入内容；
						$scope.changeText = function(keyresult1) {
							$scope.edittext = keyresult1;
						};
						// 关键结果失去焦点的时候，把上面文字去掉
						$scope.disText = function() {
							$scope.edittext = "";
						};

						// 初始化开始结束时间，初始化为周一和周五
						var currentday = new Date().getDay();
						if (currentday == 0) {
							currentday = 7;
						}
						var beginmonth = new Date(new Date().getTime()
								- (currentday - 1) * 24 * 3600 * 1000)
								.getMonth() + 1;
						var begindate = new Date(new Date().getTime()
								- (currentday - 1) * 24 * 3600 * 1000)
								.getDate();
						var endmonth = new Date(new Date().getTime()
								+ (5 - currentday) * 24 * 3600 * 1000)
								.getMonth() + 1;
						var enddate = new Date(new Date().getTime()
								+ (5 - currentday) * 24 * 3600 * 1000)
								.getDate();
						// 初始化周数
						$scope.weeknum = getWeekNumber(
								new Date().getFullYear(), beginmonth, begindate);
						// deleteNewPlan()，删除最后一个子数据，周计划
						$scope.deleteNewPlan = function() {
							$scope.weekplans.pop();
						};
						// addNewPlan()，新增周计划里面子项数据
						$scope.addNewPlan = function() {
							$scope.weekplans.push({
								resultSource1 : $scope.resultSources[0],
								beginmonth1 : beginmonth,
								begindate1 : begindate,
								endmonth1 : endmonth,
								enddate1 : enddate,
								efficiency1 : $scope.efficiencys[1],
								effect1 : $scope.effects[1],
								efficiencyboss1 : $scope.efficiencys[1],
								effectboss1 : $scope.effects[1],
							});
						};
						// 总权重、总评分
						$scope.totalquanzhong = 0;
						$scope.totalselfper = 0;
						$scope.totalbossper = 0;
						// 计算总权重、总评分
						$scope.gettotalper = function() {
							$scope.totalquanzhong = 0;
							$scope.totalselfper = 0;
							$scope.totalbossper = 0;
							for (var i = 0; i < $scope.weekplans.length; i++) {
								if ($scope.weekplans[i].keyresultper1 != undefined
										&& $scope.weekplans[i].selfper1 != undefined
										&& $scope.weekplans[i].bossper1 != undefined) {
									$scope.totalquanzhong = $scope.totalquanzhong
											+ parseInt($scope.weekplans[i].keyresultper1);
									$scope.totalselfper = $scope.totalselfper
											+ $scope.weekplans[i].selfper1;
									$scope.totalbossper = $scope.totalbossper
											+ $scope.weekplans[i].bossper1;
								}
							}
							;
						};

						// 根据效果及效率得出分数
						$scope.geteff = function(eff) {
							var b = 0;
							switch (eff) {
							case '提前完成超出预期':
								b = 1.3;
								break;
							case '按时完成超出预期':
								b = 1.1;
								break;
							case '提前完成符合预期':
								b = 1.1;
								break;
							case '按时完成符合预期':
								b = 1.0;
								break;
							case '提前完成效果一般':
								b = 1.0;
								break;
							case '滞后超出预期':
								b = 0.9;
								break;
							case '按时完成效果一般':
								b = 0.9;
								break;
							case '滞后符合预期':
								b = 0.8;
								break;
							case '滞后效果一般':
								b = 0.5;
								break;
							case '未启动效果很差':
								b = 0;
								break;
							default:
								break;
							}
							return b;
						};
						// 计算自己的得分,z代表数组本身，
						// selforboss,0代表变动的是分数，1代表变动的是自己的东西，2代表变动的是上级打分
						$scope.getselfper = function(z, selfOrBoss) {
							var b = 0;
							if (z.keyresultper1 == undefined
									|| z.keyresultper1 == null) {
								z.keyresultper1 = 0;
							}
							var a = "";
							if (selfOrBoss == 0) {
								a = z.efficiency1 + z.effect1;
								b = $scope.geteff(a);
								z.selfper1 = Math.round(z.keyresultper1 * b
										* 100) / 100;
								a = z.efficiencyboss1 + z.effectboss1;
								b = $scope.geteff(a);
								z.bossper1 = Math.round(z.keyresultper1 * b
										* 100) / 100;
							} else if (selfOrBoss == 1) {
								a = z.efficiency1 + z.effect1;
								b = $scope.geteff(a);
								z.selfper1 = Math.round(z.keyresultper1 * b
										* 100) / 100;
							} else {
								a = z.efficiencyboss1 + z.effectboss1;
								b = $scope.geteff(a);
								z.bossper1 = Math.round(z.keyresultper1 * b
										* 100) / 100;
							}
							$scope.gettotalper();
						};
						$scope.selectPerson = null;
						// 初始化时间插件,人员组织结构树
						$scope.init = function() {
							// 初始化人员组织tree配置。
							var setting = {
								data : {
									simpleData : {
										enable : true
									}
								},
								callback : {
									onClick : function(event, treeId, treeNode) {
										$scope.selectPerson = treeNode.selectID;
										$scope.isDeptOrTeam = treeNode.isDeptOrTeam;
										$("#checkoutPerson").val(treeNode.name);
										document.getElementById("aa").style.display = "none";
									}
								}
							};
							// 初始化部门人员信息。
							// $scope.zNodes
							// isDeptOrTeam ,0代表公司，1代表部门，2代表项目组，3代表个人。
							// selectID,公司、部门、项目组、个人的id
							$http(
									{
										method : 'GET',
										url : "weekAndMonth/selectDeptOrTeam.do",
										headers : {
											'Content-Type' : 'application/x-www-form-urlencoded'
										},
										params : {},
									}).success(
									function(data) {// 这里的data，就是后台传递过来的数据
										if (data.tag == "success") {
											$scope.zNodes = data.zNodes;
											$.fn.zTree.init($("#treeDemo"),
													setting, $scope.zNodes);
										} else {
											toaster.pop({
												type : 'error',
												title : '提示',
												body : "获取部门列表失败",
												timeout : 2000
											});

										}
									}).error(
									function(data, status, headers, config) {
										toaster.pop({
											type : 'error',
											title : '提示',
											body : "请求出错了",
											timeout : 2000
										});

									});

							var pickeradd = $('#datetimepickeradd')
									.datetimepicker({
										format : 'yyyy-mm-dd',
										maxDate : new Date(2020, 5, 22),
										minDate : new Date(),
										startingDay : 1,
										weekStart : 1,
										startDate : new Date(2000, 5, 22),
										autoclose : true,
										minView : 2,
										todayBtn : true,
										todayHighlight : true,
										language : 'cn'
									// showMeridian : true,
									});

							var pickeradd2 = $('#datetimepickeradd2')
									.datetimepicker({
										format : 'yyyy-mm-dd',
										maxDate : new Date(2020, 5, 22),
										minDate : new Date(),
										startingDay : 1,
										weekStart : 1,
										startDate : new Date(2000, 5, 22),
										autoclose : true,
										minView : 2,
										todayBtn : true,
										todayHighlight : true,
										language : 'cn'
									// showMeridian : true,
									});
							$scope.beginTimeadd = new Date()
									.format('yyyy-MM-dd');
							$scope.endTimeadd = new Date().format('yyyy-MM-dd');
							var picker1 = $('#datetimepicker1').datetimepicker(
									{
										format : 'yyyy-mm-dd',
										maxDate : new Date(2020, 5, 22),
										minDate : new Date(),
										startingDay : 1,
										weekStart : 1,
										startDate : new Date(2000, 5, 22),
										autoclose : true,
										minView : 2,
										todayBtn : true,
										todayHighlight : true,
										language : 'cn'
									// showMeridian : true,
									});
							var picker2 = $('#datetimepicker2').datetimepicker(
									{
										format : 'yyyy-mm-dd',
										maxDate : new Date(2020, 5, 22),
										minDate : new Date(),
										startingDay : 1,
										weekStart : 1,
										startDate : new Date(2000, 5, 22),
										autoclose : true,
										minView : 2,
										todayBtn : true,
										todayHighlight : true,
										language : 'cn',
										initialDate : new Date(),
									});

							$('#datetimepicker1').datetimepicker().on(
									'show',
									function(e) {
										$('#datetimepicker1').datetimepicker(
												'update');
									});
							$('#datetimepicker2').datetimepicker().on(
									'show',
									function(e) {
										$('#datetimepicker2').datetimepicker(
												'update');
									});
							// 动态设置最小值
							$('#datetimepicker1').datetimepicker().on(
									'changeDate',
									function(e) {
										var a = $("#datetimebegin").val();
										var b = $("#datetimeend").val();
										$('#datetimepicker2').datetimepicker(
												'setStartDate', e.date);
										if (a > b) {
											$("#datetimeend").val(a);
											$scope.endTime = a;
										}
									});
							// 动态设置最大值
							$('#datetimepicker2').datetimepicker().on(
									'changeDate',
									function(e) {
										var a = $("#datetimebegin").val();
										var b = $("#datetimeend").val();
										$('#datetimepicker1').datetimepicker(
												'setEndDate', e.date);
										if (a > b || a == "") {
											$("#datetimebegin").val(b);
											$scope.beginTime = b;
										}
									});

						};
						// 点击打开人员组织结构方法。
						$scope.selectPersonal = function() {
							document.getElementById("aa").style.display = "block";
						};

						// 创建一个方法，定义一个属性来接收当天日期
						$scope.today = function() {
							$scope.myDate = new Date();
						};

						$scope.today();

						// 清空 myDate
						$scope.clear = function() {
							$scope.myDate = null;
						}
						// 创建open方法 。
						// 下面默认行为并将opened 设为true
						$scope.open = function($event) {
							$event.preventDefault();
							$event.stopPropagation();
							$scope.opened = true;
						}

						$scope.disabled = function(date, mode) {
							return (mode === 'day' && (date.getDay() === 0 || date
									.getDay() === 6))
						}

						$scope.toggleMin = function() {
							$scope.minDate = $scope.minDate ? null : new Date();
						}

						$scope.toggleMin();

						$scope.dateOptions = {
							formatDay : 'dd',
							formatMonth : 'MM',
							formatYear : 'yyyy',
							formatDayHeader : 'EEE',
							formatDayTitle : 'MMMM yyyy',
							formatMonthTitle : 'yyyy',
							maxDate : new Date(2020, 5, 22),
							minDate : new Date(),
							startingDay : 1
						}
						// 日期格式数组
						$scope.myDateformats = [ 'yyyy-MM-dd', 'dd-MMMM-yyyy',
								'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate' ];
						// 将日期格式数组第0项设为默认日期格式
						$scope.myDefaultDateFormat = $scope.myDateformats[0];
						$scope.firstPage = 1;
						$scope.pageNum = 5;
						$scope.page = 1;
						// 默认下方分页不显示。
						$scope.isShowPage = false;
						// 加载页面
						$scope.load_page = function(page) {
							if (page < 1) {
								toaster.pop({
									type : 'error',
									title : '提示',
									body : "已经是第一页了",
									timeout : 2000
								});
							} else if (page > $scope.pageCount) {
								toaster.pop({
									type : 'error',
									title : '提示',
									body : "已经是最后一页了",
									timeout : 2000
								});
							} else {
								$scope.p_current = page;
								$scope.sub(page);
								$scope.testCases = [];
								for (var a = (page - 1) * 10; a < (page) * 10; a++) {
									if (a < $scope.resultAllLength) {
										$scope.testCases
												.push($scope.testCasesAll[a]);
									}
								}
								$scope.beginAndEnd($scope.p_current);
							}
						}
						// 点击翻页
						$scope.sub = function(page) {
							if (page >= $scope.pageNum) {
								$scope.firstPage = page
										- Math.floor($scope.pageNum / 2);
							} else {
								$scope.firstPage = 1;
							}
							if ($scope.firstPage > $scope.pageCount
									- $scope.pageNum) {
								$scope.firstPage = $scope.pageCount
										- $scope.pageNum + 1;
							}
							$scope.pages = setPage($scope.pageCount,
									$scope.pageNum, $scope.firstPage);
							$scope.page = page;
						}
						// 是否显示选择框
						$scope.isShowSelect = function(x) {
							if (x == '公共') {
								return false;
							}
							return true;
						}
						// 关闭添加的弹出框
						$scope.pupuClose = function() {
							$("#spm").hide();
							$(".Popup").hide(10);
							$scope.isAdd = false;
							$scope.isEdit = false;
							$scope.demandId = 0;
							$scope.beginTimeadd = '';
							$scope.endTimeadd = '';
							$scope.demandContent = '';
							//$scope.statusFordemandadd = 1;
							$scope.isShowEditBtn = true;
							$scope.currenteditUsersid = null;
							$scope.isShowExportBtn = false;
							$scope.ssfordemand = $scope.oldssfordemand;
						}

						// 多选然后标识
						var signGroup = [];
						// 记录整条信息，便于删除后直接从js上删除该信息。
						var signGroupAll = [];
						$scope.isSelected = function(currentrow, isCheck) {
							if (isCheck == true) {
								signGroupAll.push(currentrow);
								signGroup.push(currentrow.caseid);
							} else {
								signGroupAll.removeByValue(currentrow);
								signGroup.removeByValue(currentrow.caseid);
							}
							return currentrow;
						}
						// 鼠标点击事件
						$scope.show = function(x) {
							if (x != undefined && x != null && x.trim() != "") {
								toaster.pop({
									type : 'success',
									title : '提示',
									body : x,
									timeout : 1000
								});
							}
						};

						// 打开编辑框
						$scope.openEdit = function(x, y) {
							showPopupLayer();
							$scope.oldssfordemand = $scope.ssfordemand;
							$scope.demandId = x.id;
							$scope.beginTimeadd = x.starttime;
							$scope.endTimeadd = x.endtime;
							$scope.demandContent = x.projectname;
							$scope.statusFordemandadd = x.state == '启用' ? 1 : 2;
							$scope.isEdit = true;
						};

						// 显示是提审还是待审还是通过
						$scope.whatName = function(x) {
							return "编辑";
						}
						// 添加按钮
						$scope.addDemandBtn = function() {
							$scope.isAdd = true;
							$scope.statusFordemandadd = 1;
							$scope.oldssfordemand = $scope.ssfordemand;
						}
						// 主添加方法
						$scope.addDemand = function() {
							// 每次添加前再算一遍！！！
							isContine = true;
							if ($scope.beginTimeadd == undefined
									|| $scope.beginTimeadd == 'undefined'
									|| $scope.endTimeadd == undefined
									|| $scope.endTimeadd == 'undefined'
									|| $scope.demandContent == undefined
									|| $scope.demandContent == 'undefined'
									|| $scope.demandContent.trim() == '') {
								toaster.pop({
									type : 'error',
									title : '有未填写的项！！！',
									body : '完善后再提交！！！',
									timeout : 2000
								});
								isContine = false;
							}

							if (isContine && $scope.isEdit) {
								$http(
										{
											method : 'POST',
											url : 'weekAndMonth/editDemand.do',
											data : $
													.param({
														id : $scope.demandId,
														beginTimeadd : encodeURI($scope.beginTimeadd),
														endTimeadd : encodeURI($scope.endTimeadd),
														demandContent : encodeURI($scope.demandContent),
														statusFordemandadd : $scope.statusFordemandadd
													}),
											headers : {
												'Content-Type' : 'application/x-www-form-urlencoded'
											}

										}).success(function(data) {
									$scope.pupuClose();
									if (data.tag == "success") {
										toaster.pop({
											type : 'success',
											title : '提示',
											body : data.msg,
											timeout : 2000
										});
									} else {
										toaster.pop({
											type : 'error',
											title : '刚才没编辑成功哦',
											body : data.msg,
											timeout : 2000
										});
									}
								})
							} else if (isContine && $scope.isAdd)
								$http(
										{
											method : 'POST',
											url : 'weekAndMonth/insertDemand.do',
											data : $
													.param({
														beginTimeadd : encodeURI($scope.beginTimeadd),
														endTimeadd : encodeURI($scope.endTimeadd),
														demandContent : encodeURI($scope.demandContent),
														statusFordemandadd : $scope.statusFordemandadd
													}),
											headers : {
												'Content-Type' : 'application/x-www-form-urlencoded'
											}

										}).success(function(data) {
									$scope.pupuClose();
									if (data.tag == "success") {
										toaster.pop({
											type : 'success',
											title : '提示',
											body : data.msg,
											timeout : 2000
										});
									} else {
										toaster.pop({
											type : 'error',
											title : '刚才没提交成功哦',
											body : data.msg,
											timeout : 2000
										});
									}
								})
						}

						// 主查询方法
						$scope.selectDemand = function() {
							var endTime = $scope.endTime == undefined ? null
									: $scope.endTime;
							var beginTime = $scope.beginTime == undefined ? null
									: $scope.beginTime;
							$scope.onlySeeSelf = ($scope.onlySeeSelf == undefined || $scope.onlySeeSelf == false) ? false
									: true;

							$http(
									{
										method : 'GET',
										url : "weekAndMonth/selectDemand.do",
										headers : {
											'Content-Type' : 'application/x-www-form-urlencoded'
										},
										params : {
											beginTime : encodeURI(beginTime),
											endTime : encodeURI(endTime),
											onlySeeSelf : $scope.onlySeeSelf,
											statusFordemand : $scope.ssfordemand
										},
									})
									.success(
											function(data) {// 这里的data，就是后台传递过来的数据
												if (data.tag == "success") {
													for (i = 0; i < data.data.length; i++) {
														var newDate = new Date();

														newDate
																.setTime(data.data[i].starttime);
														data.data[i].starttime = newDate
																.format('yyyy-MM-dd');
														newDate
																.setTime(data.data[i].endtime);
														data.data[i].endtime = newDate
																.format('yyyy-MM-dd');
														if (data.data[i].state == 1) {
															data.data[i].state = '启用'
														} else {
															data.data[i].state = '禁用'
														}

													}

													$scope.testCasesAll = data.data;
													// 计算结果总数
													$scope.resultAllLength = $scope.testCasesAll.length;
													// 计算总页码
													$scope.pageCount = Math
															.ceil($scope.resultAllLength / 10);
													// 本页面的记录
													$scope.testCases = [];
													for (var a = 0; a < 10; a++) {
														if (a < $scope.resultAllLength) {
															$scope.testCases
																	.push($scope.testCasesAll[a]);
														}
													}
													$scope.isShowPage = true;
													// 总页码加入到数组里面
													$scope.sub(1);
													$scope.p_current = 1;
													toaster.pop({
														type : 'success',
														title : '提示',
														body : "已查询完毕",
														timeout : 2000
													});
												} else {
													$scope.resultAllLength = 0;
													toaster.pop({
														type : 'error',
														title : '提示',
														body : "查询结果为空",
														timeout : 2000
													});
													$scope.testCases = [];
													$scope.isShowPage = false;
												}
												$scope
														.beginAndEnd($scope.p_current);
											}).error(
											function(data, status, headers,
													config) {
												toaster.pop({
													type : 'error',
													title : '提示',
													body : "请求出错了",
													timeout : 2000
												});

											});
						}
						// 分页算法
						$scope.calculateIndexes = function(x) {
							var indexes = [];
							for (var i = 1; i <= x; i++) {
								indexes.push(i);
							}
							return indexes;
						};
						// 计算第一条和最后一条是多少？
						$scope.beginAndEnd = function(p_current) {
							$scope.start = (p_current - 1) * 10 + 1;
							$scope.end = (p_current) * 10;
							if ($scope.resultAllLength < 1) {
								$scope.resultAllLength = 0;
								$scope.start = 0;
								$scope.end = 0;
							}
							if ($scope.end > $scope.resultAllLength) {
								$scope.end = $scope.resultAllLength;
							}
						}

						// 审核状态
						var examineGroup = [];
						$scope.examine = function(x, isChecked) {
							if (isChecked == true) {
								if (x != 2) {
									examineGroup.push(x);
								} else {
									examineGroup.push(2);
									examineGroup.push(3);
								}
							} else {
								if (x != 2) {
									examineGroup.removeByValue(x);
								} else {
									examineGroup.removeByValue(2);
									examineGroup.removeByValue(3);
								}
							}
						};
						// 测试方法
						$scope.test = function() {
							alert($scope.pass);
						};
					});
	// 添加测试用例,弹出框,开启
	popupLayer("btn_add", "Popup");
})
// 点击方法显示popuplayer
function showPopupLayer() {
	$("#spm").show();
	var target = $(".Popup");
	var targetWidth = target.outerWidth();
	var targetHeight = target.outerHeight();
	if (isIE(6)) {
		$("#spm").hide();
		var top = $(document).scrollTop() + $(window).height() / 2;
		target.css({
			"top" : top + "px"
		});
		$(window).scroll(function() {
			var top = $(document).scrollTop() + $(window).height() / 2;
			target.css({
				"top" : top + "px"
			});
		});
	}
	target.css({
		"margin-top" : -parseInt(targetHeight / 2) + "px",
		"margin-left" : -parseInt(targetWidth / 2) + "px"
	});
	target.show();
	return false;
}
function setPage(pageCount, num, first) {// 创建保存页码数组的函数
	// first第一页的页码
	var pages = []; // 创建分页数组
	var page = pageCount;
	if (page <= num) {
		for (var i = 1; i <= page; i++) {
			pages.push(i);
		}
	}
	if (page > num) {
		for (var i = first; i < first + num; i++) {
			pages.push(i);
		}
	}
	return pages;
}

String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
};
Array.prototype.removeByValue = function(val) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] == val) {
			this.splice(i, 1);
			break;
		}
	}
};
Date.prototype.format = function(format) {
	var date = {
		"M+" : extra(this.getMonth() + 1),
		"d+" : extra(this.getDate()),
		"h+" : extra(this.getHours()),
		"m+" : extra(this.getMinutes()),
		"s+" : extra(this.getSeconds()),
		"q+" : extra(Math.floor((this.getMonth() + 3) / 3)),
		"S+" : extra(this.getMilliseconds())
	};
	if (/(y+)/i.test(format)) {
		format = format.replace(RegExp.$1, (this.getFullYear() + '')
				.substr(4 - RegExp.$1.length));
	}
	for ( var k in date) {
		if (new RegExp("(" + k + ")").test(format)) {
			format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? date[k]
					: ("00" + date[k]).substr(("" + date[k]).length));
		}
	}
	return format;
};
// 补位函数。
function extra(x) {
	// 如果传入数字小于10，数字前补一位0。
	if (x < 10) {
		return "0" + x;
	} else {
		return x;
	}
}
function indexOf(arr, item) {
	if (Array.protopy.indexOf) {
		return arr.indexOf(item);
	} else {
		for (var i = 0; i < arr.length; i++) {
			if (arr[i] === item)
				return i;
			else
				return -1;
		}
	}
}
/**
 * 判断年份是否为润年
 * 
 * @param {Number}
 *            year
 */
function isLeapYear(year) {
	return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
/**
 * 获取某一年份的某一月份的天数
 * 
 * @param {Number}
 *            year
 * @param {Number}
 *            month
 */
function getMonthDays(year, month) {
	return [ 31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ][month]
			|| (isLeapYear(year) ? 29 : 28);
}
26 /**
	 * 获取某年的某天是第几周
	 * 
	 * @param {Number}
	 *            y
	 * @param {Number}
	 *            m
	 * @param {Number}
	 *            d
	 * @returns {Number}
	 */
function getWeekNumber(a, b, c) {

	// 判断当前日期为当年第几周
	// date1是当前日期
	// date2是当年第一天
	// d是当前日期是今年第多少天
	// 用d + 当前年的第一天的周差距的和在除以7就是本年第几周
	// 那一年第一天是星期几 var
	var yearFirstDay = new Date(a, 0, 1).getDay() || 7;
	var date1 = new Date(a, parseInt(b) - 1, c), date2 = new Date(a, 0, 1), d = Math
			.round((date1.valueOf() - date2.valueOf()) / 86400000);
	if (yearFirstDay == 1) {
		return Math.ceil((d + ((date2.getDay() + 1) - 1)) / 7) + 1;
	} else {
		return Math.ceil((d + ((date2.getDay() + 1) - 1)) / 7);
	}
}